// var i;
// exports.GameConst = exports.IGameConst = void 0;
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var l = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.prop_game_level = [2, 4, 6, 8];
//         t.prop_pop_level = [12, 16, 20];
//         t.prop0_origin = 1;
//         t.prop1_origin = 1;
//         t.prop2_origin = 1;
//         t.prop3_origin = 1;
//         t.prop4_origin = 2;
//         t.prop5_origin = 1;
//         t.prop6_origin = 1;
//         t.skin_enabled = !1;
//         t.pop_try_skin = 8;
//         t.pop_try_skin_count = 3;
//         t.tips_prop_time = 10;
//         t.time_prop_time = 15;
//         t.tips_duration = 5;
//         t.guide_duration = 15;
//         t.video_lattice_duration = 18;
//         t.video_lattice_unlock = 18;
//         t.warnning_time1 = 60;
//         t.warnning_time2 = 30;
//         t.warnning_time3 = 15;
//         t.time_prop_duration = 30;
//         t.vit_enabled = !0;
//         t.vit_max = 5;
//         t.vit_recovery_time = 900;
//         t.vit_price = 100;
//         t.video_vit_count = 3;
//         t.money_enabled = !0;
//         t.money_max = 600;
//         t.money_valid = 300;
//         t.online_enabled = !0;
//         t.online_time_origin = 900;
//         t.online_time_increase = 300;
//         t.online_time_limit = -1;
//         t.online_reward = [1, 1, 1, 1, 100];
//         t.mission_enabled = !0;
//         t.challenge_enabled = !0;
//         t.challenge_unlock_level = 18;
//         t.challenge_reward_coin = [200, 1];
//         t.levelBox_unlock_level = 10;
//         t.starBox_unlock_star = 1e3;
//         t.levelBox_reward_coin = [200, 1];
//         t.prop0_price = 200;
//         t.prop1_price = 200;
//         t.prop2_price = 200;
//         t.prop3_price = 100;
//         t.prop4_price = 300;
//         t.prop5_price = 300;
//         t.prop6_price = 100;
//         t.revive_price = 300;
//         t.share_reward = 100;
//         t.reward_coin = 100;
//         t.share_video_coin = 100;
//         t.coin_buy_prop_enabled = !0;
//         t.pass_reward = 1;
//         t.pass_bank = 25;
//         t.video_prop_count_enter = 1;
//         t.video_prop_count_game = 1;
//         t.club_enabled = !1;
//         t.feedback_enabled = !1;
//         t.share_enabled = !1;
//         t.login_gift_enabled = !1;
//         t.lv2hard_enabled = !1;
//         t.lv2hard_level = 3;
//         t.lv2confs = null;
//         t.lvconfs = [];
//         t.lvspaceConfs = [];
//         t.showHardTitle = !1;
//         t.displaceLevel = 10;
//         t.special_enabled = !1;
//         t.special_unlock_level = 25;
//         t.special_lvconfs = [];
//         t.special_spaceConfs = [];
//         t.specail_revive = 1;
//         t.backup_level = 5;
//         t.backup_space = 1;
//         t.pay_enabled = !1;
//         t.free_coin = 20;
//         t.noads_time = 168;
//         t.vip_time = 168;
//         t.giftpack_cd = 24;
//         t.rank_enabled = !1;
//         t.new_user_ad = !1;
//         t.new_user_ad_duration = 24;
//         return t;
//     }
//     __extends(t, e);
//     return t;
// })(require("./AL_GAME_HUA_ConfigHandler").ConfigHandler);
// exports.IGameConst = l;
// var u = (function (t) {
//     function n() {
//         var e = (null !== t && t.apply(this, arguments)) || this;
//         e.typeMap = {};
//         return e;
//     }
//     __extends(n, t);
//     n.getInstance = function () {
//         return this.instance || (this.instance = new n());
//     };
//     n.prototype.destroy = function () {
//         n.instance = null;
//     };
//     n.prototype.jiazai_peizhi = function () {
//         return __awaiter(this, void 0, Promise, function () {
//             var e;
//             var t;
//             var n = this;
//             return __generator(this, function () {
//                 e = "gameConst_native";
//                 "wx" == (t = ailin_sdk_manager.getSysPlatformName())
//                     ? (e = "gameConst_wx")
//                     : "tt" == t
//                     ? (e = "gameConst_tt")
//                     : "native" == t && (e = "gameConst_native");
//                 AL_GAME_HUA_Common.Common.isDebug();
//                 return [
//                     2,
//                     this.yibu_jiazai_txt_peizhi(e)
//                         .then(function (e) {
//                             if (e) {
//                                 var t = {};
//                                 for (var o in e) {
//                                     var i = e[o];
//                                     var r = i.value;
//                                     var a = i.type;
//                                     n.typeMap[o] = a;
//                                     t[o] = r;
//                                 }
//                                 try {
//                                     n.huifu_peizhi(t);
//                                 } catch (e) {
//                                     console.error("[GameConst]", "huifu_peizhi error:", e);
//                                 }
//                                 console.log("[GameConst]", "local GameConst:", t);
//                                 return e;
//                             }
//                             return null;
//                         })
//                         .catch(function () {
//                             return null;
//                         })
//                 ];
//             });
//         });
//     };
//     n.prototype.jiazai_yuancheng_peizhi = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             return __generator(this, function () {
//                 if (ailin_sdk_manager.huoquYouxiZidingyiCanshu) {
//                     e = ailin_sdk_manager.huoquYouxiZidingyiCanshu();
//                     console.log("[GameConst]", "remote GameCustom:", e);
//                     if (e) {
//                         this.huifu_peizhi(e);
//                     }
//                 }
//                 return [2];
//             });
//         });
//     };
//     n.prototype.huifu_peizhi = function (t) {
//         var n;
//         var o;
//         for (var i in t) {
//             var r = t[i];
//             var a = null !== (o = this.typeMap[i]) && void 0 !== o ? o : 0;
//             r = this.jiexi_zhi(r);
//             if (0 == a) {
//                 this[i] = r;
//             } else {
//                 if (1 == a) {
//                     if (Array.isArray(r)) {
//                         if (this[i]) {
//                             (n = this[i]).push.apply(n, r);
//                         }
//                     } else {
//                         if ("object" == typeof r && null != r) {
//                             if (this[i]) {
//                                 for (var s in r) this[i][s] = r[s];
//                             }
//                         } else {
//                             this[i] = r;
//                         }
//                     }
//                 }
//             }
//         }
//     };
//     n.prototype.jiexi_zhi = function (e) {
//         if ("string" == typeof e) {
//             try {
//                 e = JSON.parse(e);
//             } catch (e) {}
//         }
//         return e;
//     };
//     n.prototype.zhuanhua_wei_json = function () {
//         var e = {};
//         for (var t in this) {
//             var n = this[t];
//             if ("function" != typeof n) {
//                 e[t] = n;
//             }
//         }
//         return e;
//     };
//     n.instance = null;
//     return n;
// })(l);
// exports.GameConst = u;


let globalIndex;
exports.GameConst = exports.IGameConst = void 0;
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");

/**
 * 游戏配置类，继承自AL_GAME_HUA_ConfigHandler.ConfigHandler
 */
class GameConfig extends require("./AL_GAME_HUA_ConfigHandler").ConfigHandler {
    // 初始化游戏配置属性
    constructor() {
        super();

        this.prop_game_level = [2, 4, 6, 8];
        this.prop_pop_level = [12, 16, 20];
        this.prop0_origin = 1;
        this.prop1_origin = 1;
        this.prop2_origin = 1;
        this.prop3_origin = 1;
        this.prop4_origin = 2;
        this.prop5_origin = 1;
        this.prop6_origin = 1;
        this.skin_enabled = false;
        this.pop_try_skin = 8;
        this.pop_try_skin_count = 3;
        this.tips_prop_time = 10;
        this.time_prop_time = 15;
        this.tips_duration = 5;
        this.guide_duration = 15;
        this.video_lattice_duration = 18;
        this.video_lattice_unlock = 18;
        this.warnning_time1 = 60;
        this.warnning_time2 = 30;
        this.warnning_time3 = 15;
        this.time_prop_duration = 30;
        this.vit_enabled = true;
        this.vit_max = 5;
        this.vit_recovery_time = 900;
        this.vit_price = 100;
        this.video_vit_count = 3;
        this.money_enabled = true;
        this.money_max = 600;
        this.money_valid = 300;
        this.online_enabled = true;
        this.online_time_origin = 900;
        this.online_time_increase = 300;
        this.online_time_limit = -1;
        this.online_reward = [1, 1, 1, 1, 100];
        this.mission_enabled = true;
        this.challenge_enabled = true;
        this.challenge_unlock_level = 18;
        this.challenge_reward_coin = [200, 1];
        this.levelBox_unlock_level = 10;
        this.starBox_unlock_star = 1000;
        this.levelBox_reward_coin = [200, 1];
        this.prop0_price = 200;
        this.prop1_price = 200;
        this.prop2_price = 200;
        this.prop3_price = 100;
        this.prop4_price = 300;
        this.prop5_price = 300;
        this.prop6_price = 100;
        this.revive_price = 300;
        this.share_reward = 100;
        this.reward_coin = 100;
        this.share_video_coin = 100;
        this.coin_buy_prop_enabled = true;
        this.pass_reward = 1;
        this.pass_bank = 25;
        this.video_prop_count_enter = 1;
        this.video_prop_count_game = 1;
        this.club_enabled = false;
        this.feedback_enabled = false;
        this.share_enabled = false;
        this.login_gift_enabled = false;
        this.lv2hard_enabled = false;
        this.lv2hard_level = 3;
        this.lv2confs = null;
        this.lvconfs = [];
        this.lvspaceConfs = [];
        this.showHardTitle = false;
        this.displaceLevel = 10;
        this.special_enabled = false;
        this.special_unlock_level = 25;
        this.special_lvconfs = [];
        this.special_spaceConfs = [];
        this.specail_revive = 1;
        this.backup_level = 5;
        this.backup_space = 1;
        this.pay_enabled = false;
        this.free_coin = 20;
        this.noads_time = 168;
        this.vip_time = 168;
        this.giftpack_cd = 24;
        this.rank_enabled = false;
        this.new_user_ad = false;
        this.new_user_ad_duration = 24;
    }
}

exports.IGameConst = GameConfig;

/**
 * 游戏常量类，继承自GameConfig
 */
class GameConst extends GameConfig {
    constructor() {
        super();
        this.typeMap = {};
    }

    /**
     * 获取GameConst的单例
     * @returns {GameConst} 单例
     */
    static getInstance() {
        if (!this.instance) {
            this.instance = new GameConst();
        }
        return this.instance;
    }

    /**
     * 销毁单例
     */
    destroy() {
        GameConst.instance = null;
    }

    /**
     * 加载配置文件
     * @returns {Promise} 返回加载的配置文件
     */
    async jiazai_peizhi() {
        let configType = "gameConst_native";
        const platformName = ailin_sdk_manager.getSysPlatformName();
        
        if (platformName === "wx") {
            configType = "gameConst_wx";
        } else if (platformName === "tt") {
            configType = "gameConst_tt";
        } else if (platformName === "native") {
            configType = "gameConst_native";
        }

        AL_GAME_HUA_Common.Common.isDebug();
        try {
            const config = await this.yibu_jiazai_txt_peizhi(configType);
            if (config) {
                const restoredConfig = {};
                for (const key in config) {
                    const item = config[key];
                    const value = item.value;
                    const type = item.type;
                    this.typeMap[key] = type;
                    restoredConfig[key] = value;
                }
                try {
                    this.huifu_peizhi(restoredConfig);
                } catch (e) {
                    console.error("[GameConst]", "huifu_peizhi error:", e);
                }
                console.log("[GameConst]", "local GameConst:", restoredConfig);
                return config;
            }
        } catch (e) {
            console.error("Error loading config:", e);
            return null;
        }
    }

    /**
     * 加载远程配置
     */
    async jiazai_yuancheng_peizhi() {
        if (ailin_sdk_manager.huoquYouxiZidingyiCanshu) {
            const customParams = ailin_sdk_manager.huoquYouxiZidingyiCanshu();
            console.log("[GameConst]", "remote GameCustom:", customParams);
            if (customParams) {
                this.huifu_peizhi(customParams);
            }
        }
    }

    /**
     * 恢复配置
     * @param {Object} config 恢复的配置
     */
    huifu_peizhi(config) {
        for (const key in config) {
            const value = config[key];
            const type = this.typeMap[key] || 0;
            const parsedValue = this.jiexi_zhi(value);
            
            if (type === 0) {
                this[key] = parsedValue;
            } else if (type === 1) {
                if (Array.isArray(parsedValue)) {
                    if (this[key]) {
                        this[key].push(...parsedValue);
                    }
                } else if (typeof parsedValue === "object" && parsedValue !== null) {
                    if (this[key]) {
                        for (const subKey in parsedValue) {
                            this[key][subKey] = parsedValue[subKey];
                        }
                    }
                } else {
                    this[key] = parsedValue;
                }
            }
        }
    }

    /**
     * 解析值
     * @param {string} value 值
     * @returns {any} 解析后的值
     */
    jiexi_zhi(value) {
        if (typeof value === "string") {
            try {
                value = JSON.parse(value);
            } catch (e) {
                console.error("Error parsing value:", e);
            }
        }
        return value;
    }

    /**
     * 转换为JSON
     * @returns {Object} JSON对象
     */
    zhuanhua_wei_json() {
        const jsonObj = {};
        for (const key in this) {
            if (typeof this[key] !== "function") {
                jsonObj[key] = this[key];
            }
        }
        return jsonObj;
    }
}

GameConst.instance = null;
exports.GameConst = GameConst;